package com.yi.student.export;

import java.util.List;

import javax.inject.Inject;

import org.hibernate.SessionFactory;
import org.hibernate.transform.Transformers;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;

import com.yi.student.dto.ExcelDto;
@Repository("exportDao")
public class ExportDaoImpl extends HibernateTemplate implements IExportDao {

	@Inject
	public void setSuperSessionFactory(SessionFactory sessionFactory){
		super.setSessionFactory(sessionFactory);
	}
	
	/**
	 * 当做报表的导出 ，等不需要hibernate 缓存的时候可以用 nativeSQL 并用非托管实体对象存储
	 * 就可以摆脱hibernate 的缓存 ，提高效率
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List listExportDate() {
		String hql = "select name , ksh , sex , xh , (CASE status WHEN '1' THEN '在校' ELSE '离校' END) as 'status' , (CASE isreword WHEN '1' THEN '奖励' ELSE '惩处' END ) AS 'isreword' from t_stu" ; 
		
		List excels = this.getSession().createSQLQuery(hql).
		setResultTransformer(Transformers.aliasToBean(ExcelDto.class)).list();
		
		return excels;
	}

	

}
